home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWViewAs.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.8 KB  |  270 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWViewAs.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWVIEWAS_H
  13. #include "FWViewAs.h"
  14. #endif
  15.  
  16. #ifndef FWSTDDEF_H
  17. #include "FWStdDef.h"
  18. #endif
  19.  
  20. #ifndef FWCONTXT_H
  21. #include "FWContxt.h"
  22. #endif
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. // ----- OS Layer -----
  29.  
  30. #ifndef FWRECSHP_H
  31. #include "FWRecShp.h"
  32. #endif
  33.  
  34. #ifndef FWPOLY_H
  35. #include "FWPoly.h"
  36. #endif
  37.  
  38. #ifndef FWPOLYSH_H
  39. #include "FWPolySh.h"
  40. #endif
  41.  
  42. #ifndef FWREGION_H
  43. #include "FWRegion.h"
  44. #endif
  45.  
  46. #ifndef FWBMPSHP_H
  47. #include "FWBmpShp.h" 
  48. #endif
  49.  
  50. #ifndef FWCFMRES_H
  51. #include "FWCFMRes.h"
  52. #endif
  53.  
  54. #ifndef FWRECT_H
  55. #include "FWRect.h"
  56. #endif
  57.  
  58. #ifndef FWICONSH_H
  59. #include "FWIconSh.h"
  60. #endif
  61.  
  62. #ifndef FWODGEOM_H
  63. #include "FWODGeom.h"
  64. #endif
  65.  
  66. #ifndef FWLINSHP_H
  67. #include "FWLinShp.h"
  68. #endif
  69.  
  70. // ----- Framework Layer -----
  71.  
  72. #ifndef FWFRAME_H
  73. #include "FWFrame.h"
  74. #endif
  75.  
  76. #ifndef FWPART_H
  77. #include "FWPart.h"
  78. #endif
  79.  
  80. #ifndef FWUTIL_H
  81. #include "FWUtil.h"
  82. #endif
  83.  
  84. // ----- OpenDoc Includes -----
  85.  
  86. #ifndef SOM_ODFacet_xh
  87. #include <Facet.xh>
  88. #endif
  89.  
  90. // ----- Platform Includes -----
  91.  
  92. #if defined(FW_BUILD_MAC) && !defined(__ICONS__)
  93. #include <Icons.h>
  94. #endif
  95.  
  96. //========================================================================================
  97. // RunTime Info
  98. //========================================================================================
  99.  
  100. #ifdef FW_BUILD_MAC
  101. #pragma segment fwpart2
  102. #endif
  103.  
  104. //========================================================================================
  105. // CLASS FW_CViewAs
  106. //========================================================================================
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CViewAs::FW_CViewAs
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CViewAs::FW_CViewAs(Environment *ev, ODTypeToken viewAs) :
  113.     fShape(NULL),
  114.     fViewAs(viewAs),
  115.     fCachedUsedShape(NULL)
  116. {
  117. FW_UNUSED(ev);
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CViewAs::~FW_CViewAs
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_CViewAs::~FW_CViewAs()
  125. {
  126.     delete fShape;
  127.     fShape = NULL;
  128.     
  129.     FW_SOMEnvironment ev;
  130.     PrivInvalidateUsedShape(ev);
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. //    FW_CViewAs::Unload
  135. //----------------------------------------------------------------------------------------
  136.  
  137. void FW_CViewAs::Unload(Environment* ev)
  138. {
  139.     delete fShape;
  140.     fShape = NULL;
  141.  
  142.     PrivInvalidateUsedShape(ev);
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CViewAs::Load
  147. //----------------------------------------------------------------------------------------
  148.  
  149. void FW_CViewAs::Load(Environment* ev, FW_CFrame* frame)
  150. {
  151.     if (fShape == NULL)
  152.     {
  153.         if (fViewAs == FW_CPart::fgViewAsThumbnailToken)
  154.         {
  155.             fThumbnailUsedRect.Set(FW_kZeroPoint, FW_IntToFixed(64), FW_IntToFixed(64));
  156.             
  157.             FW_CBitmap bitmap(64, 64, 8);
  158.             
  159.             {
  160.                 FW_CBitmapContext bc(ev, bitmap);
  161.                 
  162.                 FW_CRectShape::RenderRect(bc, fThumbnailUsedRect, FW_kFill, FW_kWhiteEraseInk);
  163.                 FW_CRectShape::RenderRect(bc, fThumbnailUsedRect, FW_kFrame);
  164.                 FW_CLineShape::RenderLine(bc, fThumbnailUsedRect.TopLeft(), fThumbnailUsedRect.BotRight());
  165.                 FW_CLineShape::RenderLine(bc, FW_CPoint(fThumbnailUsedRect.left - FW_kFixedPos1, fThumbnailUsedRect.bottom), 
  166.                                              FW_CPoint(fThumbnailUsedRect.right - FW_kFixedPos1, fThumbnailUsedRect.top));
  167.                 
  168.                 frame->BuildThumbnail(ev, bc, fThumbnailUsedRect);        
  169.             }
  170.             
  171.             fShape = FW_NEW(FW_CBitmapShape, (bitmap, fThumbnailUsedRect));
  172.         }
  173.         else
  174.         {
  175.             FW_Fixed iconSize = FW_IntToFixed((fViewAs == FW_CPart::fgViewAsSmallIconToken) ? 16 : 32);
  176.             FW_CIcon icon = frame->GetIcon(ev, FW_FixedToInt(iconSize));    
  177.         
  178.             FW_CRect iconRect(FW_kZeroPoint, iconSize, iconSize);
  179.             fShape = FW_NEW(FW_CIconShape, (icon, iconRect));
  180.         }
  181.     }
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    FW_CViewAs::AcquireUsedShape
  186. //----------------------------------------------------------------------------------------
  187.  
  188. ODShape* FW_CViewAs::AcquireUsedShape(Environment* ev) const
  189. {
  190.     FW_CViewAs* self = (FW_CViewAs*)this;
  191.     
  192.     if (fCachedUsedShape == NULL)
  193.     {
  194.         FW_ASSERT(fShape != NULL);
  195.         
  196.         if (fViewAs == FW_CPart::fgViewAsThumbnailToken)
  197.         {
  198.             self->fCachedUsedShape = ::FW_NewODShape(ev, fThumbnailUsedRect);
  199.         }
  200.         else 
  201.         {
  202. #ifdef FW_BUILD_MAC
  203.             FW_CIcon icon;
  204.             FW_RenderIconAlignment alignment;
  205.             FW_RenderIconTransform transform;
  206.             FW_CRect rect;
  207.             ((FW_CIconShape*)fShape)->GetGeometry(icon, rect, transform, alignment);
  208.         
  209.             RgnHandle rgn = ::FW_NewRegion();
  210.             short iconSize = (fViewAs == FW_CPart::fgViewAsSmallIconToken) ? 16 : 32;
  211.             FW_CPlatformRect bounds(0, 0, iconSize, iconSize);
  212.             ::IconSuiteToRgn(rgn, &bounds, alignment, icon.GetPlatformIcon());
  213.         
  214.             self->fCachedUsedShape = ::FW_NewODShape(ev, rgn);
  215. #endif
  216.  
  217. #ifdef FW_BUILD_WIN
  218.             FW_DEBUG_MESSAGE("Not yet implemented");
  219. #endif
  220.         }
  221.     }
  222.     
  223.     fCachedUsedShape->Acquire(ev);
  224.  
  225.     return fCachedUsedShape;
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    FW_CViewAs::Draw
  230. //----------------------------------------------------------------------------------------
  231.  
  232. void FW_CViewAs::Draw(Environment* ev, FW_CFrame* frame, ODFacet* facet, ODShape* invalidShape)
  233. {
  234.     Load(ev, frame);
  235.     
  236.     if (fViewAs == FW_CPart::fgViewAsSmallIconToken || fViewAs == FW_CPart::fgViewAsLargeIconToken)
  237.     {
  238.         FW_RenderIconTransform iconTransform = FW_kIconTransformNone;
  239.         
  240.         if (facet->GetHighlight(ev) == kODFullHighlight )
  241.             iconTransform = FW_kIconTransformSelected;
  242.         
  243.         // Check to see if the frame has been opened into a part window.
  244.         FW_CWindow* window = frame->GetPart(ev)->GetPartWindow(ev);
  245.         if (window && window->IsShown(ev) )
  246.             iconTransform |= FW_kIconTransformOpen;
  247.         
  248.         ((FW_CIconShape*)fShape)->SetIconTransform(iconTransform);
  249.     }
  250.  
  251.     FW_CFrameContext fc(ev, facet, invalidShape);
  252.     fShape->Render(fc);
  253.     
  254.     if (fViewAs == FW_CPart::fgViewAsThumbnailToken && facet->GetHighlight(ev) != kODNoHighlight)
  255.     {
  256.         FW_CRect bounds = frame->GetVisibleBounds(ev);
  257.         FW_CRectShape::RenderRect(fc, bounds, FW_kFill, FW_CInk(FW_kSystemHilite));
  258.     }
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_CViewAs::PrivInvalidateUsedShape
  263. //----------------------------------------------------------------------------------------
  264.  
  265. void FW_CViewAs::PrivInvalidateUsedShape(Environment* ev)
  266. {
  267.     if (fCachedUsedShape != NULL)
  268.         fCachedUsedShape->Release(ev);
  269.     fCachedUsedShape = NULL;
  270. }